var Main = {
  data() {
    return {
      imageUrl: ''
    };
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      // SparkMD5-readAsBinaryString
      const fileReaderBinary = new FileReader();
      fileReaderBinary.readAsBinaryString(file)
      fileReaderBinary.addEventListener('load', function (e) {
        const result = e.target.result
        const md5 = SparkMD5.hash(result)
        log('SparkMD5-readAsBinaryString', md5)
      })

      // SparkMD5-append-readAsBinaryString
      const fileReaderAppend = new FileReader();
      fileReaderAppend.readAsBinaryString(file)
      fileReaderAppend.addEventListener('load', function (e) {
        const spark = new SparkMD5();
        const result = e.target.result
        spark.append(result)
        const md5 = spark.end(true)
        log('SparkMD5-readAsBinaryString-append', md5);
      })

      // SparkMD5-readAsArrayBuffer
      const fileReaderBuffer = new FileReader();
      fileReaderBuffer.readAsArrayBuffer(file)
      var sparkArrayBuffer = new SparkMD5.ArrayBuffer();
      fileReaderBuffer.addEventListener('load', function (e) {

        const result = e.target.result
        const md5 = SparkMD5.ArrayBuffer.hash(result)
        log('SparkMD5-readAsArrayBuffer=', md5);

        const timeTemp = TimeTemp.create()
        timeTemp.start()
        sparkArrayBuffer.append(result)
        timeTemp.end()
        timeTemp.showTemp()
        const arrayMd5 = sparkArrayBuffer.end()
        log('SparkMD5-readAsArrayBuffer-append', arrayMd5 );
      })

      // SparkMD5-readAsDataURL
      const fileReaderData = new FileReader();
      fileReaderData.readAsDataURL(file)
      fileReaderData.addEventListener('load', function (e) {
        const result = e.target.result
        const md5 = SparkMD5.hash(result)
        log('SparkMD5-readAsDataURL', md5);
      })


      // md5-js --- readAsBinaryString
      const fileReaderBinary1 = new FileReader();
      fileReaderBinary1.readAsBinaryString(file)
      fileReaderBinary1.addEventListener('load', function (e) {
        const result = e.target.result
        const test = md5(result)
        log('md5-js-readAsBinaryString', test);
      })

      const fileReaderBuffer1 = new FileReader();
      fileReaderBuffer1.readAsArrayBuffer(file)
      fileReaderBuffer1.addEventListener('load', function (e) {
        const result = e.target.result
        const test = md5(result)
        log( 'md5-js-readAsArrayBuffer', test);
      })

      // 不触发上传接口
      return false

    }
  },
  created() {}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
